package com.yixun.lbx.service.impl;

import com.yixun.lbx.entity.YxProBreedKnowledge;
import com.yixun.lbx.mapper.information.BreedKnowledgeMapper;
import com.yixun.lbx.service.BreedKnowledgeServie;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class BreedKnowledgeServieImpl implements BreedKnowledgeServie {
    private final BreedKnowledgeMapper knowledgeMapper;

    public BreedKnowledgeServieImpl(BreedKnowledgeMapper knowledgeMapper) {
        this.knowledgeMapper = knowledgeMapper;
    }

    @Override
    public Integer getCount(HashMap<String, Object> map) {
        return knowledgeMapper.getCount(map);
    }

    @Override
    public List<YxProBreedKnowledge> getListByPage(HashMap<String, Object> map) {
        return knowledgeMapper.getListByPage(map);
    }

    @Override
    public int addKnowledge(HashMap<String, Object> map) {
        map.put("addTime", getDate());
        return knowledgeMapper.insertSelective(map);
    }

    @Override
    public int updateKnowledge(HashMap<String, Object> map) {
        map.put("updateTime", getDate());
        return knowledgeMapper.updateByPrimaryKeySelective(map);
    }

    @Override
    public int deleteKnowledge(HashMap<String, Object> map) {
        return knowledgeMapper.deleteByPrimaryKey(map);
    }

    @Override
    public List<YxProBreedKnowledge> getObjByArgs(YxProBreedKnowledge knowledge) {
        return knowledgeMapper.getObjByArgs(knowledge);
    }

    @Override
    public List<YxProBreedKnowledge> getSearchListByPage(HashMap<String, String> map) {
        return knowledgeMapper.getSearchListByPage(map);
    }

    private String getDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(new Date());
    }
}
